# coding="utf-8"
__author__ = 'Fan.Zhang'

import pandas as pd
import statsmodels.api as sm
import pylab as pl
import numbers as np

df = pd.read_csv("http://www.ats.ucla.edu/stat/data/binary.csv")

print df.head()
#    admit  gre   gpa  rank
# 0      0  380  3.61     3
# 1      1  660  3.67     3
# 2      1  800  4.00     1
# 3      1  640  3.19     4
# 4      0  520  2.93     4

df.columns = ["admit", "gre", "gpa", "prestige"]
print df.columns

print df.describe()

print df.std()

print pd.crosstab(df['admit'], df['prestige'], rownames=['admit'])

df.hist()
pl.show()

dummy_ranks = pd.get_dummies(df['prestige'],prefix='prestige')
print dummy_ranks.head()

cols_to_keep = ['admit','gre','gpa']
data = df[cols_to_keep].join(dummy_ranks.ix[:,'prestige_2':])
print data.head()

data['intercept'] = 1.0

train_cols = data.columns[1:]

logit = sm.logit(data['admit'], data[train_cols])

result = logit.fit()